package com.yyw.foodie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yyw.foodie.mapper.CategoryMapper;
import com.yyw.foodie.pojo.CategoryEntity;
import com.yyw.foodie.service.CategoryService;
import com.yyw.foodie.vo.CategoryTwoVo;
import com.yyw.foodie.vo.NewSixCategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 商品分类  服务实现类
 * </p>
 *
 * @author yiyw
 * @since 2021-05-22
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryEntity> implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    /**
     * 获取一级分类数据
     * @return
     */
    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<CategoryEntity> getOneCategory() {
        QueryWrapper<CategoryEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(CategoryEntity::getFatherId, 0);
        return list(queryWrapper);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<CategoryTwoVo> getCategoryByPid(Integer pid) {
        return categoryMapper.getCategoryByPid(pid);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<NewSixCategoryVo> getNewSixItems(Integer rootCatId) {
        return categoryMapper.getNewSixItemsByPid(rootCatId);
    }
}
